DOC Skip to main content

Creating Filters Directly

Update on 2026-08-11 03:31:21

ON THIS PAGE

1. Quick Start

Using ThresholdFilter as an example, complete post-processing in 3 steps:

#include <libobsensor/ObSensor.hpp>

 

// Step 1: Create the Filter

auto thresholdFilter = std::make_shared<ob::ThresholdFilter>();

 

// Step 2: Set parameters (keep depth values between 300mm and 3000mm)

thresholdFilter->setValueRange(300, 3000);

 

// Step 3: Process the frame (depthFrame comes from a FrameSet obtained via Pipeline)

auto outFrame = thresholdFilter->process(depthFrame);

if(outFrame) {

    auto processedDepth = outFrame->as<ob::DepthFrame>();

    // Use processedDepth ...

}

2. Chaining Multiple Filters

Multiple Filters can be chained together, passing the output of one Filter as the input to the next.

Chain Order (Depth Stream)

Format Conversion (FormatConvertFilter)

  → Downsampling (DecimationFilter)

    → Sequence Filtering (SequenceIdFilter)

      → Threshold Filtering (ThresholdFilter)

        → Noise Reduction (EdgeNoiseRemovalFilter/FalsePositiveFilter/

             MgcNoiseRemovalFilter/LutNoiseRemovalFilter)

          → Spatial Smoothing (SpatialAdvancedFilter/SpatialFastFilter/

                 SpatialModerateFilter)

            → Temporal Smoothing (TemporalFilter)

              → Hole Filling (HoleFillingFilter)

                → Software Alignment (Align)

                  → Point Cloud (PointCloudFilter)

⚠ Note: A slash (/) indicates optional alternatives within the same stage. Choose based on your device model and scenario requirements. Keep the relative order of Filters unchanged; reordering may produce unexpected results.

Code Example (threshold filtering → noise reduction → spatial smoothing → software alignment → point cloud):

auto thresholdFilter = std::make_shared<ob::ThresholdFilter>();

thresholdFilter->setValueRange(300, 3000);

thresholdFilter->enable(true);

 

auto edgeFilter = std::make_shared<ob::EdgeNoiseRemovalFilter>();

edgeFilter->enable(true);

 

auto spatialFilter = std::make_shared<ob::SpatialAdvancedFilter>();

spatialFilter->enable(true);

 

auto alignFilter = std::make_shared<ob::Align>(OB_STREAM_COLOR);

alignFilter->enable(true);

 

auto pointCloudFilter = std::make_shared<ob::PointCloudFilter>();

pointCloudFilter->setCreatePointFormat(OB_FORMAT_RGB_POINT);

pointCloudFilter->enable(true);

 

// Frame processing should be done in a separate thread. Do not call it directly in the frame acquisition or callback thread.

if(!frameSet) return;

auto depthFrame = frameSet->getFrame(OB_FRAME_DEPTH);

auto colorFrame = frameSet->getFrame(OB_FRAME_COLOR);

if(!depthFrame || !colorFrame) return;

 

std::shared_ptr<ob::Frame> outFrame = frameSet;

for(auto &filter : std::vector<std::shared_ptr<ob::Filter>>{

        thresholdFilter, edgeFilter, spatialFilter,

        alignFilter, pointCloudFilter}) {

    if(outFrame) {

        outFrame = filter->process(outFrame);

    }

}

// outFrame is the point cloud frame after the full processing chain

3. Other Common Interfaces

// Disable the Filter

filter->enable(false);

// Enable the Filter

filter->enable(true);

 

// Query whether the Filter is currently enabled

bool enabled = filter->isEnabled();

 

ON THIS PAGE

Add

  • Name:

  • Link Address:

Cancel

Add

  • Name:

  • Link Address:

Cancel
Questions or
Feedback?

Feedback

  • Your feedback matters! Share your thoughts on this page, report errors, or let us know how we can improve to better support your needs. If applicable, please include the specific sentence or section to help us identify and address the issue.